﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.UserData;


namespace MyDemos.Demos
{
    public partial class CalendarDemo : PhoneApplicationPage
    {
        public CalendarDemo ()
        {
            InitializeComponent ();
        }

        private void PhoneApplicationPage_Loaded (object sender, RoutedEventArgs e)
        {
            Appointments appts = new Appointments ();

            //Identify the method that runs after the asynchronous search completes.
            appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs> (Appointments_SearchCompleted);

            DateTime start = DateTime.Now;
            DateTime end = start.AddDays (50);
            int max = 20;

            //Start the asynchronous search.
            appts.SearchAsync (start, end, max, "Appointments Test #1");
        }

        void Appointments_SearchCompleted (object sender, AppointmentsSearchEventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder ();

            foreach (Appointment appt in e.Results)
            {
                sb.AppendLine (appt.Subject);
            }

            MessageBox.Show (sb.ToString ());
        }


    }
}